/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package bank.gui;

/**
 *
 * @author DCorrea
 */

/*
A basic implementation of the JDialog class.
 */
import gui.core.CoreFrame;
import gui.core.JDialog_AbstractAddAcc;
import java.awt.*;
import javax.swing.*;

public class JDialog_AddPAcc extends JDialog_AbstractAddAcc {

    private CoreFrame parentframe;
    javax.swing.JLabel JLabel1;
    javax.swing.JLabel JLabel2;
    javax.swing.JLabel JLabel3;
    javax.swing.JLabel JLabel4;
    javax.swing.JLabel JLabel5;
    javax.swing.JLabel JLabel6;
    javax.swing.JLabel JLabel7;
    javax.swing.JTextField JTextField_NAME;
    javax.swing.JTextField JTextField_CT;
    javax.swing.JTextField JTextField_ST;
    javax.swing.JTextField JTextField_STR;
    javax.swing.JTextField JTextField_ZIP;
    javax.swing.JTextField JTextField_BD;
    javax.swing.JTextField JTextField_EM;
    javax.swing.JButton JButton_OK = new javax.swing.JButton();
    javax.swing.JButton JButton_Cancel = new javax.swing.JButton();
    javax.swing.JTextField JTextField_ACNR;
    javax.swing.JLabel JLabel8;
    javax.swing.JRadioButton JRadioButton_Chk;
    javax.swing.JRadioButton JRadioButton_Sav;

    public JDialog_AddPAcc(CoreFrame parent) {

        super(parent);
        parentframe = parent;

        // This code is automatically generated by Visual Cafe when you add
        // components to the visual environment. It instantiates and initializes
        // the components. To modify the code, only use code syntax that matches
        // what Visual Cafe can generate, or Visual Cafe may be unable to back
        // parse your Java file into its visual environment.
        //{{INIT_CONTROLS
        super.setTitle("Add personal account");
        setModal(true);
        getContentPane().setLayout(null);
        setSize(283, 303);
        setVisible(false);





        JButton_OK.setText("OK");
        JButton_OK.setActionCommand("OK");
        getContentPane().add(JButton_OK);
        JButton_OK.setBounds(48, 264, 84, 24);
        JButton_Cancel.setText("Cancel");
        JButton_Cancel.setActionCommand("Cancel");
        getContentPane().add(JButton_Cancel);
        JButton_Cancel.setBounds(156, 264, 84, 24);
        getContentPane().add(JTextField_ACNR);
        JTextField_ACNR.setBounds(84, 60, 156, 20);

        //}}

        //{{REGISTER_LISTENERS
        SymMouse aSymMouse = new SymMouse();
        JRadioButton_Chk.addMouseListener(aSymMouse);
        JRadioButton_Sav.addMouseListener(aSymMouse);
        SymAction lSymAction = new SymAction();
        JButton_OK.addActionListener(lSymAction);
        JButton_Cancel.addActionListener(lSymAction);
        //}}


    }

    @Override
    protected JTextField[] makeFields() {

        JTextField_NAME = new javax.swing.JTextField();
        JTextField_CT = new javax.swing.JTextField();
        JTextField_ST = new javax.swing.JTextField();
        JTextField_STR = new javax.swing.JTextField();
        JTextField_ZIP = new javax.swing.JTextField();
        JTextField_BD = new javax.swing.JTextField();
        JTextField_EM = new javax.swing.JTextField();
        JTextField_ACNR = new javax.swing.JTextField();


        JTextField_NAME.setBounds(84, 84, 156, 20);

        JTextField_CT.setBounds(84, 132, 156, 20);

        JTextField_ST.setBounds(84, 156, 156, 20);

        JTextField_STR.setBounds(84, 108, 156, 20);

        JTextField_ZIP.setBounds(84, 180, 156, 20);

        JTextField_BD.setBounds(84, 204, 156, 20);

        JTextField_EM.setBounds(84, 228, 156, 20);

        JTextField_ACNR.setBounds(84, 60, 156, 20);

        return new JTextField[]{JTextField_NAME, JTextField_CT, JTextField_ST,
                    JTextField_STR, JTextField_ZIP, JTextField_BD,
                    JTextField_EM, JTextField_ACNR};
    }

    @Override
    protected JLabel[] makeLabels() {
        JLabel1 = new javax.swing.JLabel();
        JLabel2 = new javax.swing.JLabel();
        JLabel3 = new javax.swing.JLabel();
        JLabel4 = new javax.swing.JLabel();
        JLabel5 = new javax.swing.JLabel();
        JLabel6 = new javax.swing.JLabel();
        JLabel7 = new javax.swing.JLabel();
        JLabel8 = new javax.swing.JLabel();


        JLabel1 = makeALabel("Name");
        JLabel1.setBounds(12, 84, 48, 24);

        JLabel2 = makeALabel("Street");
        JLabel2.setBounds(12, 108, 48, 24);

        JLabel3 = makeALabel("City");
        JLabel3.setBounds(12, 132, 48, 24);

        JLabel4 = makeALabel("State");
        JLabel4.setBounds(12, 156, 48, 24);

        JLabel5 = makeALabel("ZIP");
        JLabel5.setBounds(12, 180, 48, 24);

        JLabel6 = makeALabel("Birthdate");
        JLabel6.setBounds(12, 204, 48, 24);

        JLabel7 = makeALabel("Email");
        JLabel7.setBounds(12, 228, 48, 24);

        JLabel8 = makeALabel("Acc Nr");
        JLabel8.setBounds(12, 60, 48, 24);

        return new JLabel[]{JLabel1, JLabel2, JLabel3, JLabel4, JLabel5, JLabel6,
                    JLabel7, JLabel8};


    }

    @Override
    protected JRadioButton[] makeRadios() {
        JRadioButton_Chk = new javax.swing.JRadioButton();
        JRadioButton_Sav = new javax.swing.JRadioButton();


        JRadioButton_Chk.setText("Checkings");
        JRadioButton_Chk.setActionCommand("Checkings");

        JRadioButton_Chk.setBounds(36, 0, 84, 24);
        JRadioButton_Sav.setText("Savings");
        JRadioButton_Sav.setActionCommand("Savings");

        JRadioButton_Sav.setBounds(36, 24, 84, 24);

        return new JRadioButton[]{JRadioButton_Chk, JRadioButton_Sav};
    }

    protected JLabel makeALabel(String label) {

        JLabel tempLabel = new JLabel();

        tempLabel.setText(label);
        tempLabel.setForeground(java.awt.Color.black);
        return tempLabel;

    }
    //{{DECLARE_CONTROLS

    //}}
    class SymMouse extends java.awt.event.MouseAdapter {

        public void mouseClicked(java.awt.event.MouseEvent event) {
            Object object = event.getSource();
            if (object == JRadioButton_Chk) {
                JRadioButtonChk_mouseClicked(event);
            } else if (object == JRadioButton_Sav) {
                JRadioButtonSav_mouseClicked(event);
            }
        }
    }

    void JRadioButtonChk_mouseClicked(java.awt.event.MouseEvent event) {
        //When Checking radio is clicked make this radio on
        //and make Saving account radio off
        JRadioButton_Chk.setSelected(true);
        JRadioButton_Sav.setSelected(false);
    }

    void JRadioButtonSav_mouseClicked(java.awt.event.MouseEvent event) {
        //When Saving radio is clicked make this radio on
        //and make Checking account radio off
        JRadioButton_Chk.setSelected(false);
        JRadioButton_Sav.setSelected(true);

    }

    class SymAction implements java.awt.event.ActionListener {

        public void actionPerformed(java.awt.event.ActionEvent event) {
            Object object = event.getSource();
            if (object == JButton_OK) {
                JButtonOK_actionPerformed(event);
            } else if (object == JButton_Cancel) {
                JButtonCalcel_actionPerformed(event);
            }
        }
    }

    void JButtonOK_actionPerformed(java.awt.event.ActionEvent event) {
        parentframe.accountnr = JTextField_ACNR.getText();
        parentframe.clientName = JTextField_NAME.getText();
        parentframe.street = JTextField_STR.getText();
        parentframe.city = JTextField_CT.getText();
        parentframe.zip = JTextField_ZIP.getText();
        parentframe.state = JTextField_ST.getText();
        parentframe.email = JTextField_EM.getText();
        parentframe.birthdate = JTextField_BD.getText();
        if (JRadioButton_Chk.isSelected()) {
            parentframe.accountType = "Checking";
        } else {
            parentframe.accountType = "Saving";
        }
        parentframe.newaccount = true;
        dispose();
    }

    void JButtonCalcel_actionPerformed(java.awt.event.ActionEvent event) {
        //make this frame invisible if Cancel button is clicked
        dispose();
    }
}
